package cn.cn.day17;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestRunnable {
    public static void main(String[] args) {
        Ticket t=new Ticket();
        /*Thread t1=new Thread(t);
        Thread t2=new Thread(t);
        Thread t3=new Thread(t);
        Thread t4=new Thread(t);
        t1.start();
        t2.start();
        t3.start();
        t4.start();*/
        ExecutorService pool = Executors.newFixedThreadPool(4);
        for (int i=0;i<4;i++){
            pool.execute(t);
        }
    }
}
class Ticket implements Runnable{
    int num=100;
    Object o=new Object();
    @Override
    public void run() {
        while (true){
            synchronized (o){
                if (num>0){
                   /* try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }*/
                    System.out.println(Thread.currentThread().getName()+"="+num--);
                }
                if (num<=0)break;
            }

        }
    }
}